package com.example.crt_dispatching_center.service.impl;

import com.example.crt_dispatching_center.entity.ElectricityCost;
import com.example.crt_dispatching_center.entity.Fare;
import com.example.crt_dispatching_center.mapper.FareMapper;
import com.example.crt_dispatching_center.service.FareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.*;

@Service
public class FareServiceImpl implements FareService {
    @Autowired
    private FareMapper fareMapper;

    @Override
    public Map<String, List<?>> getFare() {
        LocalDate endDate = LocalDate.now();
        LocalDate startDate = endDate.minusDays(7);
        List<LocalDate> date=new ArrayList<>();
        List<Fare> fareform=fareMapper.findByDateBetween(startDate, endDate);
        List<Float> fare=new ArrayList<>();
        for(Fare fare1:fareform)
        {
            Float fare2=fare1.getFare();
            fare.add(fare2);
            date.add(fare1.getDate());

        }
        Map<String, List<?>> map = new HashMap<>();
        map.put("date", date);
        map.put("fare",fare);
        return map;
    }
}
